layui.use([ 'element', 'form', 'laydate' ], function() {
	var element = layui.element(), form = layui.form(),laydate = layui.laydate;

	//表单校验
	form.verify({
		username : function(value) {

		},
		nickname : function(value) {

		},
		userdesc : function(value) {

		}
	});

	form.on('submit(formSubmit)', function(data) {

		var parames = {};

		var roleUser = new Array()
		$("#binding option").each(function(){
			var selectValue = $(this).val();
			roleUser[roleUser.length] = selectValue;
		});

		var permission = new Array()
		$("#permission option").each(function(){
			var selectValue = $(this).val();
			permission[permission.length] = selectValue;
		});

		parames.roleUser = roleUser.toString();
		parames.permission = permission.toString();

		var parames = $.extend(parames, data.field);

		$.post(rootPath + "/system/roleUpdate.shtml", parames, function(result) {
			if (!result.status) {
				layer.msg(result.message, {
					icon : 5,
					shift : 6
				});
			} else {
				parent.layer.close(parent.layer.index);
				parent.layer.msg('更新成功', {
					icon : 1
				});
				parent.refreshRoleList();
			}
		}, "json");
		return false;
	});

	var id = $("#id").val();
	$("#role_bind_user").empty().load(rootPath + "/system/goRoleBindUser.shtml?id="+id, function() {
		form.render();
	});
	
	$("#role_bind_resource").empty().load(rootPath + "/system/goRoleBindPermission.shtml?id="+id, function() {
		form.render();
	});

});